<?php
namespace App\Logics;
use App\Models\GoodsImgModel;
use Illuminate\Support\Facades\DB;

//逻辑处理
class GoodsImgLogic extends BaseLogic{


    public function __construct( )
    {

    }


    //添加数据
    public static function add(array $data){
        $ob=new GoodsImgModel();
        foreach($data as $k=>$v){
            $ob->$k=$v;
        }
        return  $ob->save();
    }

    //获取一条数据
    public static function getOne($img_id,array $fields=['*']){
        $img_id=(int)$img_id;

        $data=GoodsImgModel::where('img_id',$img_id)->select($fields)->first();
        return ob_to_array($data);
    }

    //根据商品id获取图片
    public static function getListByGoodsId($goods_id,array $fields=['*']){
        $goods_id=(int)$goods_id;

        $data=GoodsImgModel::where('goods_id',$goods_id)->select($fields)->get();
        return ob_to_array($data);
    }





}
